<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:insert="~{include :: header('修改帮助菜单')}" />
    <th:block th:insert="~{include :: datetimepicker-css}" />
    <th:block th:insert="~{include :: summernote-css}" />
</head>
<body class="hold-transition">
<div class="container-fluid mb-2">
        <form class="form-horizontal m" id="form-helpmenu-edit" th:object="${helpMenu}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group row" style="margin-top: 30px">
                <label class="col-sm-2 col-form-label text-sm-right">名称</label>
                <div class="col-sm-3">
                    <input name="name" th:field="*{name}" placeholder="请输入菜单名称" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group row">
                <label class="col-sm-2 col-form-label text-sm-right">排序</label>
                <div class="col-sm-2">
                    <input name="sort" th:field="*{sort}" class="form-control" type="text">
                </div>
                <div style="color: red;font-size: 12px;line-height: 34px">*倒序</div>
            </div>
            <div class="form-group row">
                <label class="col-sm-2 col-form-label text-sm-right">外链</label>
                <div class="col-sm-2">
                    <input  name="linkBuilding" th:field="*{linkBuilding}" class="form-control" type="text">
                </div>
                <div style="color: red;font-size: 12px;line-height: 34px">*(选填)外链为空则显示帮助内容，不为空则跳转到外链!</div>
            </div>
            <div class="form-group row">
                <label class="col-sm-2 col-form-label text-sm-right">内容</label>
                <div class="col-sm-8">
                    <input id="noticeContent" th:field="*{content}" name="content" type="hidden">
                    <div id="editor" class="summernote"></div>
                </div>
            </div>

        </form>
    </div>
    <th:block th:insert="~{include :: footer}" />
    <th:block th:insert="~{include :: datetimepicker-js}" />
    <th:block th:insert="~{include :: summernote-js}" />
    <script type="text/javascript">
        var prefix = "/help";
        $("#form-helpmenu-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            var sHTML = $('.summernote').summernote('code');
            $("#noticeContent").val(sHTML);
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit.json", $('#form-helpmenu-edit').serialize());
            }
        }

        $(function() {
            $('.summernote').summernote({
                placeholder: '请输入公告内容',
                height : 192,
                lang : 'zh-CN',
                followingToolbar: false,
                callbacks: {
                    onImageUpload: function (files) {
                        sendFile(files[0], this);
                    }
                }
            });
            var content = $("#noticeContent").val();
            $('#editor').summernote('code', content);
        });

        // 上传文件
        function sendFile(file, obj) {
            var data = new FormData();
            data.append("file", file);
            $.ajax({
                type: "POST",
                url: "/upload/image.json",
                data: data,
                cache: false,
                contentType: false,
                processData: false,
                dataType: 'json',
                success: function(result) {
                    if (result.code === 0) {
                        $(obj).summernote('editor.insertImage', result.data.src, result.data.title);
                    } else {
                        $.modal.alertError(result.msg);
                    }
                },
                error: function(error) {
                    $.modal.alertWarning("图片上传失败。");
                }
            });
        }
    </script>
</body>
</html>